<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="120px">
      <el-form-item label="询价单编号" prop="enquiryCode">
        <el-input
          v-model="queryParams.enquiryCode"
          placeholder="请输入询价单编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="报价单编号" prop="quotationCode">
        <el-input
          v-model="queryParams.quotationCode"
          placeholder="请输入报价单编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="供应商" prop="vendorName">
        <el-input
          v-model="queryParams.vendorName"
          placeholder="请输入供应商"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="代理人" prop="agentUserName">
        <el-input
          v-model="queryParams.agentUserName"
          placeholder="请输入代理人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="报价时间" prop="params">
        <el-date-picker
          clearable
          v-model="queryParams.params"
          type="daterange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          value-format="yyyy-MM-dd"
          placeholder="请选择报价时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
    <el-table border v-loading="loading" :data="quotationList">
      <el-table-column label="报价单编号" align="center" prop="quotationCode">
        <template slot-scope="scope">
          <el-button
            type="text"
            @click="handleView(scope.row)"
          >{{ scope.row.quotationCode }}
          </el-button>
        </template>
      </el-table-column>
      <el-table-column label="询价单编号" align="center" prop="enquiryCode">
        <template slot-scope="scope">
          <el-button
            type="text"
            @click="handleEnquiryView(scope.row)"
          >{{ scope.row.enquiryCode }}
          </el-button>
        </template>
      </el-table-column>
      <el-table-column label="供应商编码" align="center" prop="vendorCode"/>
      <el-table-column label="供应商名称" align="center" prop="vendorName"/>
      <el-table-column label="报价时间" align="center" prop="quotationTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.quotationTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="交货日期" align="center" prop="deliveryDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.deliveryDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="状态" align="center" prop="status">
        <template slot-scope="scope">
          <span v-if="scope.row.status === '0'">报价中</span>
          <span v-if="scope.row.status === '1'">报价完成</span>
        </template>
      </el-table-column>
      <el-table-column label="代理人" align="center" prop="agentUserName"/>
      <el-table-column label="含税金额" align="center" prop="taxAmount"/>
      <el-table-column label="不含税金额" align="center" prop="noTaxAmount"/>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <QuotationInfoView ref="quotationInfoView"></QuotationInfoView>
    <EnquiryInfoView ref="enquiryInfoView"></EnquiryInfoView>
  </div>
</template>

<script>
import {listQuotation} from "@/api/mes/cg/quotation";
import QuotationInfoView from "@/views/mes/cg/quotation/infoView.vue";
import EnquiryInfoView from "@/views/mes/cg/enquiry/infoView.vue";
export default {
  name: "QuotationList",
  components: {EnquiryInfoView, QuotationInfoView},
  data() {
    return {
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 采购管理-报价单表格数据
      quotationList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        enquiryCode: null,
        quotationCode:null,
        vendorName: null,
        agentUserName: null,
        params: [],

      },

    };
  },
  created() {
    this.getList();

  },
  methods: {
    /** 查询采购管理-报价单列表 */
    getList() {
      this.loading = true;
      const query = {...this.queryParams};
      if (query.params && query.params.length === 2) {
        query.params = {
          beginTime: query.params[0],
          endTime: query.params[1]
        };
      } else {
        query.params = null;
      }
      listQuotation(query).then(response => {
        this.quotationList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    handleView(row){
      this.$refs.quotationInfoView.init(row.id)
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    handleEnquiryView(row){
      this.$refs.enquiryInfoView.init(row.enquiryId);
    }
  },
};
</script>
